﻿#pragma execution_character_set("utf-8")
#ifndef COMMUNICATEUPDATEDELEGATE_H
#define COMMUNICATEUPDATEDELEGATE_H
#include <QObject>
#include <QThread>
#include "../CommunicateDelegate/hmicommunicate.h"
#include "communicatedelegate_global.h"

class CommunicateNormalDelegate;
class   CommunicateUpdateDelegate : public QThread
{
    Q_OBJECT
public:
    CommunicateUpdateDelegate();
    ~CommunicateUpdateDelegate();
public slots:
    void updateControllerInfo_ioInitial();

public:

    int setUserInfo(UserInfo userInfoIn);
    int setUpdateTimerPeriod(int originUpdatePeriodIn, int maxUpdatePeriodIn, int deltaAdjustIn);
    int getVMarkPositionInWorld(struct PositionInfo_hmi &positionReturn);
    int getVehiclePosition_specified(int typeIn, struct PositionInfo_hmi &positionReturn);

    bool isConnectedStatus();
    /**
     * @brief getValue                          执行更新函数
     */
    void updateControllerInfo();//not used
    void updateControllerInfo_oneshotTransmit();


    //**********************************************
    /**
     * @brief updateFunctionInit                更新函数 获取 控制器初始化状态
     * @return
     */
    int getFunctionInitState();
    /**
     * @brief updateFunctionMsg                 更新函数 获取消息
     * @return
     */
    bool updateFunctionMessage(std::vector<Message> &messageVectorOut);//合并gsoap传送
    /**
     * @brief updateFunction                    更新函数 LV1 基础配置类数据
     */
    bool updateFunctionLV1(UpdateDataLv1 &updateDataLv1Out);
    /**
     * @brief updateFunction                    更新函数 LV2 运行状态,文件,点位数据
     */
    bool updateFunctionLV2(UpdateDataLv2 &updateDataLv2Out);
    bool updateFunctionLV2_all();
    bool updateFunctionLV2_agv(VehicleBasicInfo &vehicleInfoOut);

    int getCurrentMapName(std::string &mapNameOut);
    int getAllPointCloud_translated(std::vector<struct PointCloudData_3D> &pointCloudOut);
//    bool updateFunctionLV2_singlePositions();
//    bool updateFunctionLV2_vehiclePositionsInfo();
    /**
     * @brief updateFunctionLV3                 更新函数 LV3 从LV2中分离IO数据 到此处
     * @return
     */
    bool updateFunctionLV3(UpdateDataLv3 &updateDataLv3Out);

    //*******************************************************

    /**
     * @brief updateCoordInfo                   更新 坐标系数据
     * @return
     */
    bool updateCoordInfo(std::vector<HmiToolCoordinateInformation > &recvToolCoordinateOut,
                         std::vector<HmiUserCoordinateInformation > &recvUserCoordinateOut);
    /**
     * @brief updateDefaultFile                 更新 缺省数据
     * @return
     */
    bool updateDefaultFile(std::string &defaultUserFileOut);

<<<<<<< HEAD
=======
private:
    void initialTime();
    void wait_period(void);
    void run();

    int getControllerAllInformation(bool isContainIoData, bool isContainAgvData,
                                             bool isContainPointCloud, struct ControllerInformationAll &infoOut);
    void login_initial();
    void updateControllerInfo_inial();
    void updateControllerInfo_lv1();
    void updateControllerInfo_lv2SucessLogic();
    int updateControllerInfo_lv3(UpdateDataLv3 &updateDataLv3Out);
    void updateControllerInfo_defaultProgramFile();

    int gsoapGetAllIONamesInfo(QVector <QVector <QString> > &ioMsgData);
>>>>>>> dev

signals:
    void runningProgramFileChanged();
    //通知 程序编辑
    void editProgramSignal();

    //通知 顶部栏 跟新
    void topViewCoordSizeSignal();

    //通知 IO 数据重新初始化
    void ioViewInitSignal();

    //通知 profile 重新tree
    void proFileViewInitSignal();

public slots:
    void tryToConnect(QString hmiVersionInfo);
    //登录与初始化*********
    /**
     * @brief updateTmpInfo
     */
    void updateTmpInfo(QString serverIP);

    /**
     * @brief timeOrderWork                     定时跟新globaldata
     */
    void timeOrderWork();


public:
     HmiCommunicate *hmiCommunicate;
<<<<<<< HEAD

    //用于临时缓存
    struct UserInfo tmpUserInfo;
    QString tmpServerIp;
    QByteArray tmpServerIpArray;

=======

    //用于临时缓存
    struct UserInfo tmpUserInfo;
    QString tmpServerIp;
    QByteArray tmpServerIpArray;

    /**
     * @brief communicateNormalDelegate         gsoap通信类
     */
    CommunicateNormalDelegate *communicateNormalDelegate;
>>>>>>> dev
    //


    /**
     * @brief hmiTimeInitFlag       hmi初始化准备到哪个状态的标志
     */
    int hmiInitialStatusFlag;

    /**
     * @brief reConnectCount        重连的标志(80ms一次定时器,累计50次就重连一次)
     */
    int reConnectCount;

    /**
     * @brief lv2FalseCount         LV2 失败累计
     */
    int lv2FalseCount;

//    double maxTime2,minTime2,maxTime3,minTime3;
//    double pTime2,pTime3;
//    int p2,p3;

private:
    /**
     * @brief timerOrder            定时器:对应timeOrderWork()
     */
    QTimer *timerOrder;
    bool isConnected;
    QMutex usingMutex;
    int minUpdatePeriod;//ms
    int currentUpdatePeriod;
    int maxUpdatePeriod;
    int deltaAdjust;

    int cycle_ns;
    uint64_t wakeup_time ;


};

#endif // COMMUNICATEUPDATEDELEGATE_H
